//
//  BaseViewController.m
//  showzhu
//
//  Created by mac on 15/8/14.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "BaseViewController.h"
//#import "HYCircleLoadingView.h"

@interface BaseViewController (){

    UIImageView *jiazai_imageView;
}

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.tabBarController.tabBar.hidden = YES;
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
//    self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
}

#pragma mark -网络加载动画
//-(UIView *)loadAnimation
//{
//    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, __kWidth, __kHeight)];
//    view.backgroundColor=[UIColor colorWithWhite:0.3f alpha:0.2f];
//    
//    UIView *mainView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, __kWidth - 80, 40)];
//    mainView.backgroundColor=[UIColor whiteColor];
//    mainView.center=view.center;
//    [view addSubview:mainView];
//    
//    HYCircleLoadingView *loadView=[[HYCircleLoadingView alloc]initWithFrame:CGRectMake((__kWidth-80)/2-50, 7.5, 25, 25)];
//    loadView.lineWidth=2.0f;
//    loadView.lineColor=Color(14, 104, 250);
//    [loadView startAnimation];
//    [mainView addSubview:loadView];
//    
//    ToolLabel *loadLabel=[[ToolLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(loadView.frame)+10, 7.5, 55, 25)];
//    [loadLabel setText:@"加载中..." txtFont:[UIFont systemFontOfSize:14] txtColor:[UIColor darkGrayColor]];
//    [mainView addSubview:loadLabel];
//    
//    return view;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)clickedBackButton:(UIButton *)sender {

}

//点击重试按钮
- (void)clickedRetyButton {

}

#pragma mark 懒加载

-(UIView *)topBar {
    
    if (!_topBar) {
        _topBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWith, 55)];
        //阴影部分
//        _topBar.layer.shadowColor = [UIColor blackColor].CGColor;
//        _topBar.layer.shadowOffset = CGSizeMake(0, 3);
//        _topBar.layer.shadowOpacity = 0.3;
        
        [self.view addSubview:_topBar];
    }
    return _topBar;
}

-(UIButton *)backButton {
    
    if (!_backButton) {
        _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _backButton.frame = CGRectMake(0, 15, 40, 40);
        [_backButton addTarget:self action:@selector(clickedBackButton:) forControlEvents:UIControlEventTouchUpInside];
        [_backButton setImage:[UIImage imageNamed:@"return_btn.png"] forState:UIControlStateNormal];
        [_backButton setImage:[UIImage imageNamed:@"return_btn_click.png"] forState:UIControlStateHighlighted];
        [self.topBar addSubview:_backButton];
    }
    return _backButton;
}

-(UILabel *)titleLabel {
    
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 25, screenWith - 100, 20)];
        _titleLabel.textColor = [self colorWithHexString:@"FFFFFF" withAlpha:1];
        _titleLabel.center = CGPointMake(screenWith/2.0, _titleLabel.center.y);
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.topBar addSubview:_titleLabel];
    }
    return _titleLabel;
}

///Users/xdd/Desktop/实现放大/image
- (void) shakeToShow:(UIView*)aView{
    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    animation.duration = 240;
    NSMutableArray *values = [NSMutableArray array];
    for (int i; i< 240; i++) {
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0, 1.0, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(-1.0, 1.0, 1.0)]];
//        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
//        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0, 1.0, 1.0)]];
    }
    
    animation.values = values;
    [animation setAutoreverses:YES];  //原路返回的动画一遍
    [aView.layer addAnimation:animation forKey:nil];
    
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
    //UIStatusBarStyleDefault = 0 黑色文字，浅色背景时使用
    //UIStatusBarStyleLightContent = 1 白色文字，深色背景时使用
}

- (UIColor *) colorWithHexString: (NSString *)color withAlpha:(double)alpha {
    
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:alpha];
}

- (void)viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}
//- (void)startHud{
//
//    
//    jiazai_imageView = [[UIImageView alloc] init];
//    jiazai_imageView.frame = CGRectMake(10, 0, 27, 46);
//    jiazai_imageView.image = [UIImage imageNamed:@"logo__"];
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    hud.mode = MBProgressHUDModeCustomView;
////    hud.customView = jiazai_imageView;
////    [self shakeToShow:hud.customView];
//    hud.labelText = @"正在拼命加载中。。。";
//    //    [MBProgressHUD hideHUDForView:self.view animated:YES];
//}
//- (void)endHud{
//
//     [MBProgressHUD hideHUDForView:self.view animated:YES];
//}

- (void)waringAction:(NSString *)string{

    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:string delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alter show];
}

//- (NSString *)nsstring_Joining_Together:(NSString *)string{
//
//    return [NSString stringWithFormat:@"%@%@", All_URL,string];
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
